<template>
	<view class="mainpadding2" style="padding-bottom: 150rpx;">
		<view class="mainpadding_top ffffff radius" style="position: relative;" v-for="(item,index) in list.data"
			:key="item.id" @click="selectitem(item)">
			<view class="lanlable">{{item.subject.name}}</view>
			<view class="flexleft pdl">
				<view class="headimg" style="position: relative;">
					<image :src="item.teacher.avatar" class="headimg" mode=""></image>
					<view class="zaixian" v-if="item.teacher.status=='normal'"></view>
					<view class="lixian" v-else></view>
				</view>
				<view class="flexcolumnbet margin_left2" style="height: 100rpx;">
					<view class="hei_text titletext bold">{{item.teacher.username}}</view>
					<view class="lan_text main_size">我的班级：{{item.classname}}</view>
				</view>
			</view>
			<view class="flexright margin_top">
				<view class="lanlable2 radius flexleft" @click="phone(item.mobile)">
					<u-icon name="phone" color="#3478f5" size="16"></u-icon>
					<view class="xiaolan margin_left1">电话</view>
				</view>
				<view class="honglable2 margin_left2 radius flexleft" @click="jiebang(item.id)">
					<u-icon name="lock-open" color="#ff0000" size="16"></u-icon>
					<view class="xiaohong margin_left1">解绑</view>
				</view>
			</view>
		</view>
		<view class="posibottom flexbetween mainpadding">
			<view class="resetbtn" @click="jumpurl('/pages_mine/shenhejd')">审核进度</view>
			<view class="surebtn" @click="jumpurl('/pages_mine/tianjials')">添加老师</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				type:"",
			}
		},
		onLoad(options) {
			if(options.type){
				this.type = options.type
			}
			this.init()
		},
		methods: {
			selectitem(item){
				if(this.type==1){
					let data = {
						id:item.teacher_id,
						name:item.teacher.username,
					}
					uni.$emit("checkTeacher",data)
					uni.navigateBack(1)
				}
				
			},
			init(isPage, page) {
				let _this = this;
				httpRequest.request('/api/teacher/getmyteacherlist', 'GET', {
					page: page || 1,
					state: 2,
				}, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			jumpurl(url) {
				uni.navigateTo({
					url
				})
			},
			phone(p) {
				uni.makePhoneCall({
					phoneNumber: p.toString()
				}).catch((e) => {
					// console.log(e)  //用catch(e)来捕获错误{makePhoneCall:fail cancel}
				})
			},
			jiebang(id){
				httpRequest.modal('提示', '确定解绑吗？', true, (res) => {
					if (res) {
						httpRequest.request('/api/teacher/del_myteacher', 'POST', {
							id
						}, false, false, true).then(res => {
							httpRequest.toast(res.msg);
							if(res.code==1){
								this.init()
							}
						}).catch(err => {
							httpRequest.toast(err.msg);
						})
					}
				})
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.honglable2 {
		border: 1rpx solid #ff0000;
		padding: 10rpx 15rpx;
	}

	.lanlable2 {
		border: 1rpx solid #3478f5;
		padding: 10rpx 15rpx;
	}
</style>